<?php

require_once 'phpmoko/ui/Widget.php';

class Hyperlink extends Widget
{
	private $text;
	private $link;
	private $target = null;

	function Hyperlink($text, $link)
	{
		parent::__construct();
		$this->text = $text;
		$this->link = $link;

		$this->setStyleName('pmk-Hyperlink');
	}

	function setTarget($target)
	{
		$this->target = $target;
	}

	function getTarget()
	{
		return $this->target;
	}

	function setText($text)
	{
		$this->text = $text;
	}

	function getText()
	{
		return $this->text;
	}

	function setLink($link)
	{
		$this->link = $link;
	}

	function getLink()
	{
		return $this->link;
	}

	function toString()
	{
		$str = '';

		$str .= '<div';

		if ($this->id != null)
			$str .= ' id="'.$this->id.'"';

		if ($this->style != null)
			$str .= ' class="'.$this->style.'"';

		$str .= '>';

		$str .= '<a href="'.htmlspecialchars($this->link).'"';
		if ($this->target != null)
			$str .= ' target="'.$this->target.'"';

		$str .= '>';

		if ($this->text instanceof Widget)
			$str .= $this->text->toString();
		else
			$str .= $this->text;
		
		$str .= '</a>';

		$str .= '</div>';

		return $str;
	}
}
?>
